package com.controller;

import com.annotation.ApiLimitedRole;
import com.annotation.DataLimited;
import com.constant.AuthRoleConstant;
import com.domain.UserMoments;
import com.dto.JsonResponse;
import com.service.impl.UserMomentsServiceImpl;
import com.support.UserSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/userMoment")
@RestController
public class UserMomentsApi {

    @Autowired
    private UserMomentsServiceImpl userMomentsServiceImpl;

    @Autowired
    private UserSupport userSupport;

    /**
     * 发布新动态
     * 用户等级等于规定等级时不能发布新动态
     */
    @ApiLimitedRole(limitedRoleCodeList = {AuthRoleConstant.ROLE_LV0})
    @DataLimited
    @PostMapping("/addUserMoment")
    public JsonResponse<String> addUserMoment(@RequestBody UserMoments userMoment) throws Exception {
        Long userId = userSupport.getCurrentUserId();
        userMoment.setUserId(userId);
        userMomentsServiceImpl.addUserMoments(userMoment);
        return JsonResponse.success();
    }

    /**
     * 获取 userId 订阅的所有动态消息
     */
    @GetMapping("/getUserSubscribedMoment")
    public JsonResponse<List<UserMoments>> getUserSubscribedMoment() {
        Long userId = userSupport.getCurrentUserId();
        List<UserMoments> result = userMomentsServiceImpl.getUserSubscribedMoments(userId);
        return new JsonResponse<>(result);
    }
}
